package org.framework.lazy.cloud.network.heartbeat.client.netty.proxy.http.advanced;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyChannelContext;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.payload.NettyProxyMsg;
import org.framework.lazy.cloud.network.heartbeat.common.advanced.proxy.http.client.AbstractHandleHttpDistributeClientProxyServerServerRouteTypeAdvanced;
import org.framework.lazy.cloud.network.heartbeat.protocol.route.RouteContext;
import org.framework.lazy.cloud.network.heartbeat.protocol.route.ServerProxyRoute;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Role;

/**
 * http 远程代理
 * 客户端：客户端远程到服务端、客户端远程到客户端
 */
@Role(BeanDefinition.ROLE_INFRASTRUCTURE)
@Slf4j
public class ClientHandleDistributeHttpClientProxyServerServerRouteTypeAdvanced extends
        AbstractHandleHttpDistributeClientProxyServerServerRouteTypeAdvanced<NettyProxyMsg> {


    /**
     * 处理当前数据
     *
     * @param nettyChannelContext       当前通道
     * @param nettyProxyMsg 通道数据
     */
    @Override
    protected void doHandler(NettyChannelContext nettyChannelContext, NettyProxyMsg nettyProxyMsg) {

        byte[] data = nettyProxyMsg.getData();
        ServerProxyRoute serverProxyRoute = JSON.parseObject(data, ServerProxyRoute.class);
        RouteContext.setRoute(serverProxyRoute);


    }
}
